<template>
	<div>
		<view class="shop" >
			<!-- <view class="shop-bg" :style="{backgroundImage : 'url('+store.image+')'}"></view> -->
			<view class="shop-info">
				<image :src="store.image" mode="aspectFill"></image>
				<view class="shop-desc">
					<text>{{store.name}}</text>
				</view>
			</view>
		</view>
		
		<view class="shop-item">
			<text class="iconfont icon-dingwei"></text>
			<span class="title">{{store.address}} {{store.detailedAddress}}</span>
			<text class="shop-call iconfont icon-dadianhua01" @click="call(store.phone)"></text>
		</view>
		
		
		<view class="shop-item2">
			<text class="iconfont icon-shijian1"></text>
			<span class="title"><label>营业时间：</label>{{startTime}}-{{endTime}}</span>
			<!-- <text class="iconfont icon-xiangyou"></text> -->
		</view>
		
		<view class="shop-item2" @click="showMaoLocation">
			<text class="iconfont icon-didiandingwei_o"></text>
			<span class="title"><label>店铺位置：</label> 据您<i class="font-color-red">{{ store.distance/1000 }}千米</i></span>
			<text class="iconfont icon-xiangyou"></text>
		</view>
		
		<view class="shop-item3">
			<text class="iconfont icon-laba"></text>
			<span class="title"><label>店铺简介：</label><i>{{store.introduction}}</i></span>
		</view>
		
	</div>
</template>

<script>
	import {
		storeListApi
	} from "@/api/store";
	import {
		isWeixin
	} from "@/utils/index";
	// #ifdef H5
	import {
		wechatEvevt,
		wxShowLocation
	} from "@/libs/wechat";
	// #endif

	import {
		mapGetters
	} from "vuex";
	// import cookie from "@/utils/store/cookie";
	const LONGITUDE = "user_longitude";
	const LATITUDE = "user_latitude";
	const MAPKEY = "mapKey";
	export default {
		name: "storeDetail",
		data() {
			return {
				page: 1,
				limit: 20,
				user_latitude: 0,
				user_longitude: 0,
				startTime : '08:00',
				endTime : '18:00',
				store:{}
			};
		},
		onLoad() {
			try {
				this.user_latitude = uni.getStorageSync('user_latitude');
				this.user_longitude = uni.getStorageSync('user_longitude');
			} catch (e) {
				// error
			}
		},
		mounted() {
			if (this.user_latitude && this.user_longitude) {
				this.getList();
			} else {
				this.selfLocation();
				this.getList();
			}
		},
		methods: {
			call(phone) {
				uni.makePhoneCall({
					phoneNumber: phone,
				});
			},
			showMaoLocation() {
				let e = this.store
				console.log(e)
				let self = this;
				// #ifdef H5
				if (self.$wechat.isWeixin()) {
					self.$wechat.seeLocation({
						latitude: Number(e.latitude),
						longitude: Number(e.longitude)
					}).then(res => {
						console.log('success');
					})
				} else {
					// #endif	
					uni.openLocation({
						latitude: Number(e.latitude),
						longitude: Number(e.longitude),
						name: e.name,
						address: `${e.address}-${e.detailedAddress}`,
						success: function() {
							console.log('success');
						}
					});
					// #ifdef H5	
				}
				// #endif
			},
			selfLocation() {
				let self = this
				// #ifdef H5
				if (self.$wechat.isWeixin()) {
					self.$wechat.location().then(res => {
						this.user_latitude = res.latitude;
						this.user_longitude = res.longitude;
						uni.setStorageSync('user_latitude', res.latitude);
						uni.setStorageSync('user_longitude', res.longitude);
						self.getList();
					})
				} else {
				// #endif	
					uni.getLocation({
						type: 'wgs84',
						success: (res) => {
							try {
								this.user_latitude = res.latitude;
								this.user_longitude = res.longitude;
								uni.setStorageSync('user_latitude', res.latitude);
								uni.setStorageSync('user_longitude', res.longitude);
							} catch {}
							self.getList();
						},
						complete: function() {
							self.getList();
						}
					});
					// #ifdef H5	
				}
				// #endif
			},
			showMaoLocation() {
				let self = this;
				// #ifdef H5
				if (self.$wechat.isWeixin()) {
					self.$wechat.seeLocation({
						latitude: Number(self.store.latitude),
						longitude: Number(self.store.longitude)
					}).then(res => {
						console.log('success1');
					})
				} else {
				// #endif	
					uni.openLocation({
						latitude: Number(self.store.latitude),
						longitude: Number(self.store.longitude),
						name: self.store.name,
						address: `${self.store.address}-${self.store.detailedAddress}`,
						success: function() {
							console.log('success2');
						}
					});
					// #ifdef H5	
				}
				// #endif
			},
			// 选中门店
			checked(e) {

				uni.$emit("handClick", {
					address: e
				});
				uni.navigateBack();
				// if (this.goName === "orders") {
				//   this.$store.commit("GET_STORE", e);
				//   this.$router.go(-1); //返回上一层
				// }
			},
			// 获取门店列表数据
			getList: function() {
				if (this.loading || this.loaded) return;
				this.loading = true;
				let data = {
					latitude: this.user_latitude || "", //纬度
					longitude: this.user_longitude || "", //经度
					page: this.page,
					limit: this.limit
				};
				storeListApi(data)
					.then(res => {
						let list = res.data.list
						if(list.length > 0){
							this.store = list[0];
							let times = this.store.dayTime.split(',');
							this.startTime = times[0]
							this.endTime = times[1]
						}
					})
					.catch(err => {
						this.$dialog.error(err);
					});
			}
		},
		onReachBottom() {
			this.getList();
		}
	};
</script>

<style scoped lang="scss">
	.shop{
		position: relative;
		top:0;
		left:0;
		right: 0;
		.shop-info{
			display: flex;
			//设置半透明背景
			backdrop-filter: blur(8px);
			background-color: white;
			// background: linear-gradient(360deg, rgba(225,225,225,0) 1%, $theme-color-opacity-2 20%, $theme-color 80% );
			align-items: center;
			padding: 30rpx ;
			image{
				width: 80rpx;
				height: 80rpx;
				border-radius: 20rpx;
			}
			.shop-desc{
				display: flex;
				flex: 1;
				flex-direction: column;
				justify-content: center;
				margin-left: 20rpx;
				text{
					font-size: 40rpx;
					font-weight: bold;
				}
				i{
					font-size: 24rpx;
					margin-top: 20rpx;
					color: white;
				}
				span{
					font-size: 24rpx;
					font-weight: bold;
					margin-top: 10rpx;
					color: white;
				}
			}
		}
		.shop-bg{
			position: absolute;
			height: 100%;
			width: 100%;
		}
	}
	.shop-item{
		border-top: 1rpx solid #f5f5f5;
		min-height: 90rpx;
		width: 100%;
		background-color: white;
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 20rpx 20rpx;
		.title{
			margin-left: 20rpx;
			margin-right: 30rpx;
			flex: 1;
		}
		.shop-call{
			border-left: 1rpx $theme-color solid;
			width: 90rpx;
		}
		text{
			text-align: center;
		}
	}
	.shop-item2{
		border-top: 1rpx solid #f5f5f5;
		min-height: 90rpx;
		width: 100%;
		background-color: white;
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 20rpx 20rpx;

		.title{
			margin-left: 20rpx;
			margin-right: 30rpx;
			flex: 1;
			display: flex;
			label{
				font-weight: bold;
				width: 160rpx;
				height: 100%;
			}
			i{
				font-style: normal;
				flex: 1;
			}
		}
	}
	.shop-item3{
		border-top: 1rpx solid #f5f5f5;
		min-height: 90rpx;
		width: 100%;
		background-color: white;
		display: flex;
		flex-direction: row;
		align-items: flex-start;
		padding: 20rpx 20rpx;
	
		.title{
			margin-left: 20rpx;
			margin-right: 30rpx;
			flex: 1;
			display: flex;
			label{
				font-weight: bold;
				width: 160rpx;
				height: 100%;
			}
			i{
				font-style: normal;
				flex: 1;
			}
		}
	}
</style>
